//
//  JKCellAppIndexHotShops.m
//  chequanbao_ios
//
//  Created by 朱凯 on 2018/1/23.
//  Copyright © 2018年 com.itboye. All rights reserved.
//

#import "JKCellAppIndexHotShops.h"

// vc
#import "JKShopsDetailVC.h"

//
#import "ByModelIndexCarousel.h"

@implementation JKCellAppIndexHotShops
{
    UIImageView *_view1;
    UIImageView *_view2;
    UIImageView *_view3;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = TABLE_COLOR;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _view1 = [UIImageView new];
    _view1.tag = 0;
    _view1.image = DEFAULT_IMAGE;
    [self.contentView addSubview:_view1];
    
    _view2 = [UIImageView new];
    _view2.tag = 1;
    _view2.image = DEFAULT_IMAGE;
    [self.contentView addSubview:_view2];
    
    _view3 = [UIImageView new];
    _view3.tag = 2;
    _view3.image = DEFAULT_IMAGE;
    [self.contentView addSubview:_view3];
    
    _view1.backgroundColor = [UIColor redColor];
    _view2.backgroundColor = [UIColor redColor];
    _view3.backgroundColor = [UIColor redColor];
    
    [_view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(@(4));
        make.right.equalTo(self.mas_centerX).offset(-2.5);
        make.height.equalTo(@((SCREEN_WIDTH - 5) / 2 * 274 / 370));
        // 设置cell高度
        make.bottom.equalTo(@(-4));
    }];
    [_view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_view1.mas_right).offset(5);
        make.top.equalTo(_view1);
        make.right.equalTo(@(-0));
        make.bottom.equalTo(_view1.mas_centerY).offset(-2);
    }];
    [_view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(_view2);
        make.top.equalTo(_view2.mas_bottom).offset(4);
    }];
    
    _view1.userInteractionEnabled = true;
    _view2.userInteractionEnabled = true;
    _view3.userInteractionEnabled = true;
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActon:)];
    [_view1 addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActon:)];
    [_view2 addGestureRecognizer:tap2];
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActon:)];
    [_view3 addGestureRecognizer:tap3];
}

- (void)setHots:(NSArray *)hots {
    
    _hots = hots;
    [hots enumerateObjectsUsingBlock:^(ByModelIndexCarousel *model, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            [_view1 setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(model.img)] placeholderImage:DEFAULT_IMAGE completed:nil];
        }
        if (idx == 1) {
            [_view2 setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(model.img)] placeholderImage:DEFAULT_IMAGE completed:nil];
        }
        if (idx == 2) {
            [_view3 setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(model.img)] placeholderImage:DEFAULT_IMAGE completed:nil];
        }
    }];
}

- (void)tapActon:(UITapGestureRecognizer *)tap {
    
    ByModelIndexCarousel *model = _hots[tap.view.tag];
    
    JKShopsDetailVC *vc = [[JKShopsDetailVC alloc] init];
    vc.seller_id = model.storeid;
    [((ByBaseVC *)self.viewController) by_normalPush:vc hasNavi:YES];

}
@end
